package com.jic.interaction.weAMOP;

import com.alibaba.fastjson.JSON;
import com.jic.common.base.vo.RestResult;
import com.jic.weamop.api.WeAMOPApi;
import com.jic.weamop.request.ChannelResponseApi;
import com.jic.weamop.request.MessageRequestApi;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


/**
 * @Auther taozhouchuan
 * @DATE 2020/11/11/13:54
 */
@RestController
@RequestMapping("/testWeAmop")
@Slf4j
@Api(value = "amop类请求测试类", tags = "AMOP", description = "amop类请求测试类")
public class TestWeAmopController {

    @Resource
    WeAMOPApi weAMOPApi;



    @ApiOperation(value = "测试方法 testAmop")
    @PostMapping("/testWeAmop")
    //客户端代码，服务端实现callback逻辑
    public RestResult<ChannelResponseApi> testAmop(@RequestBody MessageRequestApi messageRequestApi) throws Exception {
        try {

            log.debug("==========【interaction】服务消息接口，请求入参 = {}", JSON.toJSONString(messageRequestApi));
            RestResult<ChannelResponseApi> channelResponseApiRestResult = weAMOPApi.sendMessage(messageRequestApi);
            log.debug("==========【interaction】服务消息接口，请求出参 = {}",JSON.toJSONString(channelResponseApiRestResult));
            return channelResponseApiRestResult;
        } catch (Exception e) {
            log.error("======================【interaction】服务 异常 = {}==================================",e.getMessage());
        }
        return RestResult.error("9999","调用异常");

    }



}
